class EndPart extends egret.Sprite{
    private head:egret.Bitmap;
	private redBack:egret.Bitmap;
    private redBackMask:egret.Shape;

	private arr_result;
	private arr_resultMask;
	private pic_again:egret.Bitmap;
	private pic_hand:egret.Bitmap;
	private surface:egret.Bitmap;
	private logo_last:egret.Bitmap;

	private againShape:egret.Shape;

	public constructor() {
		super();
        MyData.resultNo=1;

		this.surface=new egret.Bitmap(RES.getRes("surface_png"));
		this.addChild(this.surface);
		this.width=740;
		this.height=1136;

		this.logo_last=new egret.Bitmap(RES.getRes("logo_last_png"));
        this.logo_last.scaleX=0.4;this.logo_last.scaleY=0.4;
        this.logo_last.x=680;this.logo_last.y=755;
        this.logo_last.alpha=0;
        this.addChild(this.logo_last);
		

		this.head=new egret.Bitmap(RES.getRes("head_png"));
		this.redBack=new egret.Bitmap(RES.getRes("redBack_png"));
		this.addChild(this.redBack);
		this.addChild(this.head);



        this.redBackMask=new egret.Shape();
		this.redBackMask.graphics.beginFill(0xff0000);
		this.redBackMask.graphics.drawRect(0,0,462,831);
		this.redBack.mask=this.redBackMask;

		this.addChild(this.redBackMask);
		
		this.head.width=this.head.width/959*462;
		this.head.height=this.head.height/959*462;
		this.head.x=140;this.head.y=150;
		this.redBack.x=140;this.redBack.y=150-this.redBack.height;
		this.redBackMask.x=140;this.redBackMask.y=150+58.3;



        
		this.arr_result=new Array();
	    this.arr_resultMask=new Array();
		for(var z=1;z<=8;z++){
			var resultPic=new egret.Bitmap(RES.getRes("result"+z+"_png"));
			this.arr_result.push(resultPic);
			this.addChild(resultPic);
			resultPic.x=278;resultPic.y=240;
			resultPic.width=183;resultPic.height=648;

            var resultMask=new egret.Shape();
			resultMask.graphics.beginFill(0xff0000);
			resultMask.graphics.drawRect(0,0,462,831);
			resultPic.mask=resultMask;
            this.arr_resultMask.push(resultMask);
			this.addChild(resultMask);
			resultMask.x=270;resultMask.y=100-this.redBack.height;

		}

		this.pic_again=new egret.Bitmap(RES.getRes("again_png"));
		this.addChild(this.pic_again);
		this.pic_again.x=370;
		this.pic_again.anchorOffsetX=this.pic_again.width/2;
		this.pic_again.anchorOffsetY=this.pic_again.height/2;
		this.pic_again.alpha=0;
		// this.pic_again.touchEnabled=true;


		this.pic_hand=new egret.Bitmap(RES.getRes("hand_png"));
		this.addChild(this.pic_hand);
		this.pic_hand.x=370;
		this.pic_hand.y=1100;
		this.pic_hand.anchorOffsetX=this.pic_hand.width/2;
		this.pic_hand.anchorOffsetY=this.pic_hand.height/2;
		this.pic_hand.touchEnabled=true;
		this.pic_hand.scaleX=1;
		this.pic_hand.scaleY=1;
		egret.Tween.get(this.pic_hand,{loop:true}).to({scaleX:0.8,scaleY:0.8},300).to({scaleX:1,scaleY:1},400);
		this.pic_hand.alpha=0;
        // egret.Tween.pauseTweens(this.pic_hand);

        this.againShape=new egret.Shape();
		this.againShape.graphics.beginFill(0x000000,0.5);
		this.againShape.graphics.drawRect(0,0,300,300);
		this.addChild(this.againShape);
		this.againShape.alpha=0;
		this.againShape.x=250;
		this.againShape.y=800;
		this.againShape.touchEnabled=true;
		

		this.addEventListener(egret.Event.ADDED_TO_STAGE,this.ATS,this);

	}
	private ATS(e:egret.Event){
		this.surface.alpha=0;
		egret.Tween.get(this.surface).to({alpha:1},500,egret.Ease.cubicOut);


		egret.Tween.get(this.logo_last).wait(1500).to({alpha:1,x:660},700,egret.Ease.cubicOut);

		var myThis=this;
		this.alpha=0;
		egret.Tween.get(this).to({alpha:1},200);

		this.redBack.y=150-this.redBack.height+58.3*2;
		this.arr_resultMask[MyData.resultNo-1].y=100-this.redBack.height+58.3;
		this.pic_again.y=1150;
		this.pic_hand.y=1070;
		
		egret.Tween.get(this.redBack).wait(500).to({y:150},1200,egret.Ease.cubicInOut);
        for(var z=0;z<this.arr_result.length;z++){
			this.arr_result[z].alpha=0;
		}
		this.arr_result[MyData.resultNo-1].alpha=1;

		egret.Tween.get(this.arr_resultMask[MyData.resultNo-1]).wait(500).to({y:150},1300,egret.Ease.cubicInOut);
		egret.Tween.get(this.pic_again).wait(1500).to({alpha:1,y:1050},700,egret.Ease.cubicOut);
		egret.Tween.get(this.pic_hand).wait(1800).to({alpha:1},700,egret.Ease.cubicOut);
		// setTimeout(function(){egret.Tween.resumeTweens(myThis.pic_hand)},2500)
		var myThils=this;
		setTimeout(function(){
		myThis.againShape.addEventListener(egret.TouchEvent.TOUCH_BEGIN,myThis.TB,myThis);
		},1800);
	}
	private TB(e:egret.TouchEvent){
		egret.Tween.get(this.surface).wait(1000).to({alpha:0},400,egret.Ease.cubicOut);
		egret.Tween.get(this.pic_again).to({scaleX:0.9,scaleY:0.9},150).to({scaleX:1,scaleY:1},100).to({alpha:0,y:1150},300);
		egret.Tween.get(this.pic_hand).to({y:1150,alpha:0},300);
		this.againShape.removeEventListener(egret.TouchEvent.TOUCH_BEGIN,this.TB,this);

		egret.Tween.get(this.arr_resultMask[MyData.resultNo-1]).wait(100).to({y:100-this.redBack.height+58.3},980,egret.Ease.cubicInOut);
		egret.Tween.get(this.redBack).wait(100).to({y:150-this.redBack.height+58.3*2},1000,egret.Ease.cubicInOut);

		egret.Tween.get(this).wait(1200).to({alpha:0},200);

		egret.Tween.get(this.logo_last).to({alpha:0,x:700},700,egret.Ease.cubicOut);
		this.dispatchEvent(new LoadEvent("Again"));				
	}
}